﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Ylh.Data;
using Ylh.ElvModel;
using Ylh.Enums;
using System.Data;


namespace Ylh.ElvBLL
{
    public class CustFollowElvBLL
    {
        /// <summary>
        /// 插入跟进对象
        /// </summary>
        /// <param name="ConStr">连接字符串</param>
        /// <param name="model">跟进对象</param>
        /// <returns>是否插入成功</returns>
        public bool InsertFlowInfo(string ConStr, Ylh.ElvModel.TbCustFollow model)
        {
            return TbCustFollow.InserObjedct(model, ConStr);
        }
        /// <summary>
        /// 更新跟进对象
        /// </summary>
        /// <param name="ConStr">连接字符串</param>
        /// <param name="model">跟进对象</param>
        /// <returns>是否更新成功</returns>
        public bool UpdateFlowInFo(string ConStr, Ylh.ElvModel.TbCustFollow model)
        {
            return TbCustFollow.Update(model, ConStr);
        }
        /// <summary>
        /// [ORM]删除跟进记录
        /// </summary>
        /// <param name="ConStr">连接字符串</param>
        /// <param name="CustFollow"></param>
        /// <returns>是否删除成功</returns>
        public bool Delete(string ConStr, int CustFollow)
        {
            TbCustFollow Follow = new TbCustFollow();
            OQLWhere where = new OQLWhere(Follow);
            where.AND(Follow.CustFollow, OperateType.等于, CustFollow);
            return TbCustFollow.Delete(where, ConStr);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Ylh.ElvModel.TbCustFollow GetModel(string ConStr, String CustFollow)
        {
            SqlWhere where = new SqlWhere();
            where.Info = new TbCustFollow() { CustFollow = CustFollow };
            where.SelectColumn = @" Top 1 * ";
            DataTable dt = TbCustFollow.Select(where, ConStr);
            List<TbCustFollow> li = Ylh.Pub.ConverDt2Model.DtToList<TbCustFollow>(dt);
            if (li.Count == 0)
                return new TbCustFollow() { };
            return li[0];
        }

        /// <summary>
        /// 获取是否存在上门拜访的这种情况
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="CustID">客户编号</param>
        /// <returns></returns>
        public bool GetModelByMetting(string ConStr, string CustID, String[] FllowType)
        {
            TbCustFollow flow = new TbCustFollow();
            OQLWhere where = new OQLWhere(flow);
            where.AND(flow.CustID, OperateType.等于, CustID);
            where.IN(flow.FollowType, LogicType.AND.ToString(), FllowType);
            return TbCustFollow.Delete(where, ConStr);
        }


    }
}
